import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  // {
  //   path: '/',
  //   redirect: '/login' 
  // },
  {
    path: '/',
    component: () => import('@/views/login/login.vue'),
    hidden: true
  },
  // 注册
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  // 提交
  {
    path: '/commit',
    component: () => import('@/views/commit/index'),
    hidden: true
  },
  // 审核
  {
    path: '/audit',
    component: () => import('@/views/audit/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 诊断台
  {
    path: '/accept',
    component: Layout,
    children: [{
      path: 'accepts',
      name: 'Accepts',
      component: () => import('@/views/accepts/index'),
      meta: { title: '诊断台', icon: 'dashboard' }
    }]
  },
  // 诊断管理
  {
    path: '/diagnose',
    component: Layout,
    // redirect: '/example/index',
    name: 'diagnose',
    meta: { title: '诊断管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/diagnose/index'),
        meta: { title: '诊断管理', icon: 'table' }
      },
      {
        path: 'diagnoselist',
        name: 'diagnoselist',
        component: () => import('@/views/diagnose/diagnoselist'),
        meta: { title: '诊断列表', icon: 'tree' }
      }
    ]
  },
  // 直播管理
  {
    path: '/streaming',
    component: Layout,
    name: 'streaming',
    meta: { title: '直播管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: 'streaming',
        component: () => import('@/views/streaming/index'),
        meta: { title: '直播管理', icon: 'form' }
      },
      {
        path: 'createstreaming',
        name: 'createstreaming',
        component: () => import('@/views/streaming/createstreaming'),
        meta: { title: '创建直播', icon: 'form' }
      },
      {
        path: 'startstreaming',
        name: 'startstreaming',
        component: () => import('@/views/streaming/startstreaming'),
        meta: { title: '开始直播', icon: 'form' }
      }
    ]
  },
  // 我的钱包
  {
    path: '/wallet',
    component: Layout,
    // redirect: '/wallet/index',
    name: 'Nested',
    meta: {
      title: '我的钱包',
      icon: 'nested'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/wallet/index'), // Parent router-view
        name: 'Index',
        meta: { title: '我的钱包' }
      },
      {
        path: 'downcard',
        component: () => import('@/views/wallet/downcard'),
        name: 'downcard',
        meta: { title: '提现-已绑卡' }
      },
      {
        path: 'nodowncard',
        component: () => import('@/views/wallet/nodowncard'),
        name: 'nodowncard',
        meta: { title: '提现-未绑卡' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
